﻿// -----------------------------------------------------------------------
// <copyright file="AspNetUsersInRolesData.cs" company="VDC-IT" author="LTDUC">
//      Copyright (c) VDC-IT. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------

namespace VDC.VONE.DAL
{
    using System;
    using System.Collections.Generic;
    using System.Data.SqlClient;
    using System.Reflection;
    using Microsoft.ApplicationBlocks.Data;
    using VDC.COMMON;
    using VDC.VONE.ENTITIES;
    
    /// <summary>
    /// Class access to db AspNetUsersInRoles
    /// </summary>
    public class UsersInRolesDepartmentData
    {
        /// <summary>
        /// Get AspNetUsersInRoles By Id
        /// </summary>
        /// <param name="userId">Param userId</param>
        /// <returns>Return AspNetUsersInRoles</returns>
       
        /// <summary>
        /// Get list all AspNetUsersInRoles
        /// </summary>
        /// <returns>Return list all AspNetUsersInRoles</returns>
        public IList<UsersInRolesDepartmentEN> GetUsersInRolesDepartment(string RoleName, int DepartmentId)
        {
            string methodName = MethodBase.GetCurrentMethod().DeclaringType.ToString();
            LogHelper.Instance.WriteInfo(Constants.Begin + methodName);
            try
            {
                IList<UsersInRolesDepartmentEN> lstUsersInRolesDepartment = new List<UsersInRolesDepartmentEN>();
                SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.ConnectionString, Constants.StorepProcedure.VOneAspnetUserInRolesGetRoles, RoleName, DepartmentId);
                while (reader.Read())
                {
                    UsersInRolesDepartmentEN UsersInRolesDepartment = new UsersInRolesDepartmentEN();

                    if (!reader.IsDBNull(0))
                    {
                        UsersInRolesDepartment.UserId = reader.GetInt32(0);
                    }

                    if (!reader.IsDBNull(1))
                    {
                        UsersInRolesDepartment.PostionId = reader.GetInt32(1);
                    }

                    if (!reader.IsDBNull(2))
                    {
                        UsersInRolesDepartment.DepartmentId = reader.GetInt32(2);
                    }

                    if (!reader.IsDBNull(3))
                    {
                        UsersInRolesDepartment.Name = reader.GetString(3);
                    }

                    if (!reader.IsDBNull(4))
                    {
                        UsersInRolesDepartment.UserName = reader.GetString(4);
                    }

                    if (!reader.IsDBNull(5))
                    {
                        UsersInRolesDepartment.PositionName = reader.GetString(5);
                    }

                    lstUsersInRolesDepartment.Add(UsersInRolesDepartment);
                }

                reader.Close();
                reader.Dispose();
                LogHelper.Instance.WriteInfo(Constants.End + methodName);
                return lstUsersInRolesDepartment;
            }
            catch (SqlException ex)
            {
                LogHelper.Instance.WriteError(methodName + Constants.Colon + ex.Message);
                throw new Exception(ex.ToString());
            }
        }

    
    }
}